package com.nidu.demo.notice.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.notice.convertor.NoticeConvertor;
import com.nidu.demo.notice.convertor.NoticeCriteriaConvertor;
import com.nidu.demo.notice.dto.NoticeCO;
import com.nidu.demo.notice.dto.NoticeListQry;
import com.nidu.demo.notice.gateway.NoticeGateway;
import com.nidu.demo.notice.model.Notice;
import com.nidu.demo.notice.model.NoticeCriteria;
import com.nidu.demo.user.dto.UserCO;
import com.nidu.demo.user.model.User;
import com.nidu.demo.user.model.UserCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 通知公告列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class NoticeListQryExe {

    private final NoticeGateway gateway;
    private final NoticeConvertor convertor;
    private final NoticeCriteriaConvertor criteriaConvertor;

    public MultiResponse<NoticeCO> execute(NoticeListQry qry) {
        NoticeCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<Notice> notices = gateway.listByCondition(criteria);
        List<NoticeCO> usersCOS = convertor.toClientObjects(notices);
        return MultiResponse.of(usersCOS);
    }
}
